import 'package:landlore/model/roomInfo.dart';

class RoomCheckInOut {
  int? id;
  int? roomId;
  String? roomNum;
  String? contact;
  String? address;
  String? phone;
  double? deposit;
  double? rent;
  double? otherCharge;
  double? electricityCharge;
  double? waterCharge;
  DateTime? createDate;
  String? eleImage;
  String? waterImage;
  String? extend;
  int? electricityAmount;
  int? electricityAmountLastMonth;
  int? waterAmount;
  int? waterAmountLastMonth;

  ///state:0-退房 1-入住
  int? state;

  RoomCheckInOut(
      this.id,
      this.roomId,
      this.contact,
      this.address,
      this.phone,
      this.deposit,
      this.rent,
      this.otherCharge,
      this.electricityCharge,
      this.waterCharge,
      this.createDate,
      this.state,
      this.eleImage,
      this.waterImage,
      this.extend,
      this.electricityAmount,
      this.electricityAmountLastMonth,
      this.waterAmount,
      this.waterAmountLastMonth);

  RoomCheckInOut.fromRoomInfo(
      RoomInfo data,
      double this.deposit,
      DateTime this.createDate,
      int this.state,
      String? this.eleImage,
      String? this.waterImage,
      this.extend,
      int this.electricityAmount,
      int this.electricityAmountLastMonth,
      int this.waterAmount,
      int this.waterAmountLastMonth) {
    roomId = data.id;
    contact = data.contact;
    address = data.address;
    phone = data.phone;
    rent = data.rent;
    otherCharge = data.otherCharge;
    electricityCharge = data.electricityCharge;
    waterCharge = data.waterCharge;
  }

  RoomCheckInOut.empty();

  Map<String, dynamic> toMap() {
    return {
      //插入和更新操作,均不需要操作id,而应该把id作为参数,故不需要放到toMap中
      // 'id': id,
      'roomId': roomId,
      'contact': contact,
      'address': address,
      'phone': phone,
      'deposit': deposit,
      'rent': rent,
      'otherCharge': otherCharge,
      'electricityCharge': electricityCharge,
      'waterCharge': waterCharge,
      'createDate': createDate?.millisecondsSinceEpoch,
      'state': state,
      'eleImage': eleImage,
      'waterImage': waterImage,
      'extend': extend,
      'electricityAmount': electricityAmount,
      'electricityAmountLastMonth': electricityAmountLastMonth,
      'waterAmount': waterAmount,
      'waterAmountLastMonth': waterAmountLastMonth
    };
  }

  factory RoomCheckInOut.fromMap(Map<String, dynamic> map) {
    return RoomCheckInOut(
      map['id'],
      map['roomId'],
      map['contact'],
      map['address'],
      map['phone'],
      map['deposit'],
      map['rent'],
      map['otherCharge'],
      map['electricityCharge'],
      map['waterCharge'],
      map['createDate'] != null
          ? DateTime.fromMillisecondsSinceEpoch(map['createDate'])
          : null,
      map['state'],
      map['eleImage'],
      map['waterImage'],
      map['extend'],
      map['electricityAmount'],
      map['electricityAmountLastMonth'],
      map['waterAmount'],
      map['waterAmountLastMonth'],
    );
  }

  @override
  String toString() {
    return 'RoomCheckInOut{id: $id, roomId: $roomId, contact: $contact, address: $address, phone: $phone, deposit: $deposit, rent: $rent, otherCharge: $otherCharge, electricityCharge: $electricityCharge, waterCharge: $waterCharge, createDate: $createDate, extend: $extend, state: $state}';
  }
}
